import PageBody from '@/components/school/pageBody';

const app = getApp();
import diyJson from '@/config/diy.js';
import {mapGetters} from "vuex";
import Dict from '@/components/school/dict';
import * as UserApi from '@/api/member/user.js';
import * as OrderApi from '@/api/school/order.js';
import {memberOrderById} from "../../../../api/school/order";
export const mixins = {
  components: {
    PageBody, Dict
  }
  , computed: mapGetters(['userInfo', 'schoolId', 'isLogin']), data() {
    return {
      themConfig: diyJson.commonStyle
      , scrollTop: 0
      , showLoading: true
      , datas: []
      , pageBody: {
        background: '',
        // #ifdef MP
        pageHeight: '100%',
        // #endif
        // #ifdef H5
        pageHeight: app.globalData.windows.pageBody,
        // #endif
      }
      , isReachBottom: false
      , loading: {
        status: 'nomore',
        loadingText: '加载中',
        loadmoreText: '点击加载更多'
        , dataPage: {
          current: 1,
          total: 0,
          pages: 1,
          size: 10,
        }
      }
      , memberId:''

      , dataPage: {
        current: 1,
        pages: 1,
        size: 10,
        total: 0,
      },
      agentForm: {}
    }
  }
  , onLoad(option) {
    this.memberId = option.memberId;
    this.dataList(option.memberId);
  }
  , onShow() {
  },
  mounted() {
    this.computeAmountHeight();
  },
  onPullDownRefresh() {
    this.dataList(this.memberId);
    uni.stopPullDownRefresh();
  },
  methods: {

    async computeAmountHeight() {
      const query = uni.createSelectorQuery().in(this);
      let that = this;
      query.select('.heightWrapper')
      .boundingClientRect((dome) => {
        console.log("height", dome.height)
        that.pageBody.pageHeight = that.pageBody.pageHeight - dome.height;
      })
      .exec();
    },

    // 滚到底部
    scrolltolower() {
      this.isReachBottom = true;
      this.loading.status = 'nomore';
      if (this.dataPage.current < this.dataPage.pages) {
        this.loading.status = 'loadmore';
      }
    },
    copyOrder(orderNo){
      uni.setClipboardData({
        data: orderNo,
        success: function () {
          uni.showToast({
            title: '复制成功',
            icon: 'success',
            duration: 2000
          });
        }
      });
    },
    loadmore() {
      if (this.dataPage.current < this.dataPage.pages) {
        this.loading.status = 'loading';
        UserApi.pages(
            {...this.searchParams, current: this.dataPage.current + 1}).then(
            res => {
              res.data.records.forEach(item => {
                this.datas.push(item)
              })
              this.dataPage.current = res.data.current;
              this.dataPage.pages = res.data.pages;
              this.loading.status = 'loadmore';
            })
      }
    },
    refreshList() {
      this.dataList();
    },

    dataList(params) {
      if (this.datas.length > 0) {
        this.datas.splice(0, 1);
      }
      OrderApi.memberOrderById(this.memberId,{state:3}).then(res => {
        this.datas = res.data.records;
        this.dataPage.current = res.data.current;
        this.dataPage.total = res.data.total;
        this.dataPage.pages = res.data.pages;
      })
    },
    submit(pass, item) {

    },



  }
}
